package array
{
	import flash.utils.ByteArray;
	
	import data.Method;
	
	import tag.doABC2.CPool;
	
	import util.BytesUtil;

	public dynamic class MethodArray extends Array
	{
		public function MethodArray(...parameters)
		{
			super(parameters);
		}
		
		public function fill(bytes:ByteArray):void
		{
			var cp:CPool = App.cp;
			var count:uint = BytesUtil.readU30(bytes);
			if(count > 0){
				var m:Method = null;
				for(var i:int = 0; i < count; i++){
					m = new Method();
					this[i] = m;
					m.cpool(cp);
					m.paramCount = BytesUtil.readU32(bytes);
					m.returnType = BytesUtil.readU32(bytes);
					m.params = new Array(m.paramCount);
					for(var j:int = 0; j < m.paramCount; j++){
						m.params[j] = BytesUtil.readU32(bytes);
					}
					var nameIdx:int = BytesUtil.readU32(bytes);
					if(nameIdx > 0){
						m.name = cp.cp_string[nameIdx];
					}
					else{
						m.name = "no name";
					}
					m.flags = bytes.readByte();
					if((m.flags & 0x08) == 0x08){
						m.optionCount = BytesUtil.readU32(bytes);
						m.optionIndex = new Array();
						m.optionKinds = new Array();
						for(var k:int = 0; k < m.optionCount; k++){
							m.optionIndex[k] = BytesUtil.readU32(bytes);
							m.optionKinds[k] = bytes.readByte();
						}
					}
					if((m.flags & 0x80) == 0x80){
						m.paramNames = new Array();
						for(var n:int = 0; n < m.paramCount; n++){
							m.paramNames[n] = BytesUtil.readU32(bytes);
						}
					}
					trace(m.toString());
				}
			}
		}
	}
}